/**
 * 
 */
package team.helpmephone.app.sense;

import java.security.acl.Permission;
import java.util.List;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.IBinder;
import android.util.Log;

/**
 * Copyright (c) 2010 LG-Nortel, Inc. All Rights Reserved.
 * 
 * CONFIDENTIALITY AND LIMITED USE: This software, including any software of <br>
 * third parties embodied herein, contains code, information, data and concepts <br>
 * which are confidential and/or proprietary to LG-Nortel and such third <br>
 * parties. This software is licensed for use solely in accordance with the <br>
 * terms and conditions of the applicable license agreement with LG-Nortel or <br>
 * its authorized distributor, and not for any other use or purpose. No <br>
 * redistribution of this software by any party is permitted. <br>
 * 
 * Title: ListenerSensor.java<br>
 * Description: <br>
 * Copyright: Copyright(c) 2010 LG-NORTEL ALL Rights Reserved<br>
 * Company: LG-Nortel<br>
 * 
 * @author Jonghwa, Lee
 * @version 1.0
 * @created 2010. 3. 26.
 * @modified 2010. 3. 26.
 * @product EFA R4.0 EMS
 * @sw_block Client Block
 */
public class ListenerSensor extends Service implements SensorEventListener{
	private static final String TAG = "SENSOR LISTENER";
	
	
	/* (non-Javadoc)
	 * @see android.app.Service#onCreate()
	 */
	@Override
	public void onCreate() {
		super.onCreate();
		Log.v(TAG, "Create Service");
		SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		manager.registerListener(this, manager.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER), 10);
	}
	
	
	
	/* (non-Javadoc)
	 * @see android.app.Service#onStart(android.content.Intent, int)
	 */
	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		Log.v(TAG, "Start Service");
		SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ACCELEROMETER);
		if (sensors.size() > 0) {
			manager.unregisterListener(this);
			manager.registerListener(this, sensors.get(0), SensorManager.SENSOR_DELAY_NORMAL);
			Log.v(TAG, "Sensor = " + sensors.get(0));
		}
	}



	/* (non-Javadoc)
	 * @see android.app.Service#onDestroy()
	 */
	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.v(TAG, "Destory Service");
	}



	/* (non-Javadoc)
	 * @see android.hardware.SensorEventListener#onAccuracyChanged(android.hardware.Sensor, int)
	 */
	public void onAccuracyChanged(Sensor sensor, int i) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see android.hardware.SensorEventListener#onSensorChanged(android.hardware.SensorEvent)
	 */
	public void onSensorChanged(SensorEvent sensorevent) {
		Log.v(TAG, "onSensorChange(), " + sensorevent.toString());
		Sensor sensor = sensorevent.sensor;
		switch (sensor.getType()) {
		case Sensor.TYPE_ACCELEROMETER:
			Log.v(TAG, "Sensor Accelerometer");
			break;

		default:
			break;
		}
	}

	/* (non-Javadoc)
	 * @see android.app.Service#onBind(android.content.Intent)
	 */
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

}
